package od.igor.petrov.utils;

/* ======================================= *
 *  MODEL THAT RESPONSE NEEDED COLLECTION
 * ======================================= */

import java.util.ArrayList;

import od.igor.petrov.bcontrol.DataPreparation;

public class TestTableBeanPreparedCollection {
	public TestTableBeanPreparedCollection(){
		
	}
	
	public static ArrayList<TestTableBean> getReadyResult(){
		if(inst == null){
			inst = new TestTableBeanPreparedCollection();
		}
		inst.selectNeededCollection();
		return temporaryList;
	}
	
	protected void selectNeededCollection(){
		if(sortBy == SORT_BY_ID){
			temporaryList = new DataPreparation().getSortedCollectionByID(orderDesc);
		} else if (sortBy == SORT_BY_ITEM){
			temporaryList = new DataPreparation().getSortedCollectionByItem(orderDesc);
		} else if (sortBy == SORT_BY_FIRM){
			temporaryList = new DataPreparation().getSortedCollectionByFirm(orderDesc);
		} else {
			temporaryList = new DataPreparation().getSortedCollectionByID(orderDesc);
		}
	}
	
	public static void setSortBy(int sort){
		sortBy = sort;
	}
	
	public static void setOrder(boolean order){
		orderDesc = order;
	}
	
	
	private static int sortBy = 1;
	private static boolean orderDesc = false;
	private static TestTableBeanPreparedCollection inst = null;
	private static ArrayList<TestTableBean> temporaryList = null;
	
	private final static int SORT_BY_ID = 1;
	private final static int SORT_BY_ITEM = 2;
	private final static int SORT_BY_FIRM = 3;
}
